
<template>
  <ex_super_dialog_form ref="reportDialog" v-bind="report_dialog" v-on="$listeners" @afterSubmitSuccess="submit">
  </ex_super_dialog_form>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      receiptIdList:[],
      report_dialog: {
        customClass: "dialog_auto",
        submitDataHandle: (data) => {
          const { attachedList, ...other } = data;
          if (attachedList) {
            if (this.isMainSystem || this.isWmsSystem) {
              other.anomalyAttachedList = attachedList;
            } else if (this.isTmsSystem) {
              other.attachedDTOList = attachedList;
            }
          }
          return other;
        },

        form: {
          itemClass: "form_item_default",
          inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            {
              label: "label_order_count",
              render: (h, { data }) => h('span', {},data.orderNum)
            },
            {
              label: "label_receipt_waybill_count",
              render: (h, { data }) => h('span', {},data.tmsOrderNum)
            },
            {
              label: "label_total_box_count",
              render: (h, { data }) => h('span', {}, data.totalBoxCount)
            },
            {
              label: "label_total_sku_count",
              render: (h, { data }) => h('span', {}, data.totalQuantity)
            },
            {
              key: "agentId",
              label: "label_receipt_handover_type",
              render: (h, { data }) => h('span', {}, this.$enumShow(data.tmsReceiptHandoverEnum, "TmsReceiptHandoverEnum"))
            },
            {
              if:(data)=> data.tmsReceiptHandoverEnum==='FACE_TO_FACE',
              label: "label_tms_sign_person",
              render: (h, { data }) => h('span', {}, data.handoverUsername)
            },
            {
              if:(data)=> data.tmsReceiptHandoverEnum==='EXPRESS',
              label: "label_tms_ems_no",
              render: (h, { data }) => h('span', {}, data.handoverExpressNo)
            },
            {
              label: "label_receipt_recycle_num",
              render: (h, { data }) => h('span', {}, data.handoverNum)
            },
            {
              key: "signNum",
              label: "label_tms_sign_count",
              attrs: {type:"number", maxlength: 9, "show-word-limit": true },
            },
          ],
          rules: {
            signNum: {
              required: true,
              message: this.$tt("tip_can_no_empty"),
              trigger: "blur",
            },
          },
        },
      },

    }
  },

  methods: {
    show(rows) {
      this.receiptIdList = []
      const obj = {
        tmsReceiptHandoverEnum:rows[0].tmsReceiptHandoverEnum,
        handoverExpressNo:rows[0].handoverExpressNo,
        handoverUsername:[],
        handoverNum:0,
        totalBoxCount:0,
        totalQuantity:0,
        // 后面两个字段无意义，产品要求先显示
        orderNum:rows.length,
        tmsOrderNum:rows.length
      }
      rows.forEach(item=>{
        this.receiptIdList.push(item.id)
        obj.handoverUsername.push(item.handoverUsername)
        obj.handoverNum += item.handoverNum
        obj.totalBoxCount+=item.totalBoxCount
        obj.totalQuantity+=item.totalQuantity
      })
      obj.handoverUsername = obj.handoverUsername.join(',')
      const option = Object.assign(
        {
          title: this.$t("label_tms_receipt_receipt_confirmation"),
          // submitUrl: this.$url["tms/BaseAnomalyReport"],
          // detailUrl:this.$url["wms/BaseAnomalyDetail"],
        },
        {
          data: obj,
          onlySetData: true,
          submitCall:(data,formData,submitCallResult)=>{
            submitCallResult(true,true,false)
          },
        }
      );
      this["$refs"]["reportDialog"].showNew(option);
    },
    submit(data) {
      this.$ajax({
        url: "/tms-api/task/TmsOrderReceiptInfoRpc/confirmReceiptInfo.json",
        method: 'post',
        type: 'json',
        data: {
          receiptIdList:this.receiptIdList,
          signNum:data.signNum
        },
        success: (res) => {
          this.$message.success(this.$t("label_receipt_tip_submit_confirmation"))
          this.$emit('submitSuccess')
        }
      })

    }
  }
}
</script>
